<script setup>
import { ref, onMounted } from 'vue'
import { provideLanguage, useLanguage } from './utils/language-store.js'

// 提供语言服务
provideLanguage()

// 使用语言服务
const { currentLang, changeLanguage, t } = useLanguage()

// 导航菜单
const navItems = [
  { key: 'nav.home', path: '/' },
  { key: 'nav.about', path: '/about' },
  { key: 'nav.services', path: '/services' },
  { key: 'nav.news', path: '/news' },
  { key: 'nav.contact', path: '/contact' }
]

// 当前年份
const currentYear = new Date().getFullYear()
</script>

<template>
  <div id="app">
    <!-- 导航栏 -->
    <nav class="navbar">
      <div class="nav-container">
        <div class="nav-logo">
          <router-link to="/">
            <span v-if="currentLang === 'zh'">企业官网</span>
            <span v-else>Corporate Website</span>
          </router-link>
        </div>
        <div class="nav-controls">
          <ul class="nav-menu">
            <li class="nav-item" v-for="item in navItems" :key="item.path">
              <router-link :to="item.path" class="nav-link" active-class="active" v-text="t(item.key)"></router-link>
            </li>
          </ul>
          <div class="lang-switcher">
            <button 
              :class="{ active: currentLang === 'zh' }"
              @click="changeLanguage('zh')"
            >
              中文
            </button>
            <button 
              :class="{ active: currentLang === 'en' }"
              @click="changeLanguage('en')"
            >
              EN
            </button>
          </div>
        </div>
      </div>
    </nav>
    
    <!-- 路由视图 -->
    <router-view />
    
    <!-- 页脚 -->
    <footer class="footer">
      <div class="container">
        <p>&copy; <span v-text="currentYear"></span> 
          <span v-if="currentLang === 'zh'">企业官网</span>
          <span v-else>Corporate Website</span>. 
          <span v-text="t('footer')"></span>.
        </p>
      </div>
    </footer>
  </div>
</template>

<style scoped>
#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.navbar {
  background-color: rgba(255, 255, 255, 0.95);
  box-shadow: 0 5px 20px rgba(0,0,0,0.08);
  position: sticky;
  top: 0;
  z-index: 1000;
  backdrop-filter: blur(10px);
  border-bottom: 1px solid rgba(0, 0, 0, 0.05);
  padding: 0;
}

.nav-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  height: 70px;
}

.nav-logo a {
  font-size: 1.8rem;
  font-weight: 800;
  color: transparent;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  -webkit-background-clip: text;
  background-clip: text;
  text-decoration: none;
  letter-spacing: -0.5px;
}

.nav-controls {
  display: flex;
  align-items: center;
}

.nav-menu {
  display: flex;
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav-item {
  margin: 0 2rem;
  position: relative;
}

.nav-link {
  color: #333;
  text-decoration: none;
  font-weight: 600;
  font-size: 1.1rem;
  transition: all 0.3s ease;
  padding: 0.5rem 0;
}

/* 语言切换器样式 */
.lang-switcher {
  display: flex;
  gap: 0.5rem;
  margin-left: 1.5rem;
}

.lang-switcher button {
  background: transparent;
  border: 1px solid #ddd;
  color: #666;
  padding: 5px 12px;
  border-radius: 15px;
  font-size: 0.9rem;
  cursor: pointer;
  transition: all 0.3s ease;
}

.lang-switcher button:hover {
  border-color: #667eea;
  color: #667eea;
}

.lang-switcher button.active {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border-color: transparent;
}

.nav-link::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 0;
  height: 3px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  border-radius: 2px;
  transition: width 0.3s ease;
}

.nav-link:hover, .nav-link.active {
  color: #667eea;
  background-color: transparent;
}

.nav-link:hover::after, .nav-link.active::after {
  width: 100%;
}

.footer {
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  text-align: center;
  padding: 3rem 0;
  margin-top: auto;
}

.footer p {
  font-size: 1.1rem;
  opacity: 0.9;
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 0 2rem;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .nav-container {
    flex-direction: column;
    height: auto;
    padding: 1rem;
  }
  
  .nav-menu {
    margin: 1rem 0;
    flex-wrap: wrap;
    justify-content: center;
  }
  
  .nav-item {
    margin: 0.5rem 0.8rem;
  }
}
</style>
